package qdu.edu.com.fushanf4.service.count.usertype.search2characters.count.split;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SplitStringAndSplicingTwoCharactersMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    private final Text keyOut = new Text();
    private final static IntWritable valueOut = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();

        for (int i=0; i<line.length()-1; i++) { // 注意判断是否越界
            keyOut.set(line.substring(i, i+2));
            context.write(keyOut, valueOut);
        }
    }
}
